<template>
  <div>
    <div class="header">
      <div class="header-inner">
        <h1>
          <a href="javascript:;" class="logo" data-act="icon-click">电影</a>
        </h1>

        <div class="nav">
          <div>
            <router-link
              to="/web"
              :class="{ active: curPath == '/web' }"
            >首页</router-link>
          </div>
          <div>
            <router-link
              to="/web/movies"
              :class="{ active: curPath == '/web/movies' }"
            >电影</router-link>
          </div>
          <div><a href="javascript:;" data-act="cinemas-click">影院</a></div>
          <div style="opacity: 0"><a href="javascript:;">演出</a></div>
          <div style="opacity: 0">
            <a href="javascript:;" data-act="board-click">榜单</a>
          </div>
          <div style="opacity: 0">
            <a href="javascript:;" data-act="hotNews-click">热点</a>
          </div>
          <div style="opacity: 0"><a href="javascript:;">商城</a></div>
        </div>
        <div v-if="userInfo && userInfo.avatar" class="user-info">
          <el-dropdown
            class="avatar-container right-menu-item hover-effect"
            trigger="click"
          >
            <div class="avatar-wrapper">
              <div class="user-avatar J-login">
                <img :src="userInfo.avatar">
                <span class="caret" />
              </div>
            </div>
            <el-dropdown-menu slot="dropdown">
              <router-link to="/web/personal">
                <el-dropdown-item>
                  <span style="display: block">个人中心</span>
                </el-dropdown-item>
              </router-link>
              <router-link
                v-if="userInfo.username == 'admin'"
                to="/home"
                target="_blank"
              >
                <el-dropdown-item>
                  <span style="display: block">进入后台</span>
                </el-dropdown-item>
              </router-link>
              <router-link v-if="userInfo.vip" to="/web/vipbuy">
                <el-dropdown-item>
                  <span style="display: block">会员购票</span>
                </el-dropdown-item>
              </router-link>
              <el-dropdown-item v-else @click.native="dialogVisible = true">
                <span style="display: block">开通会员</span>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">
                <span style="display: block">退出登录</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
        <div v-else class="user-info" @click="$router.push('/login')">
          <div class="user-avatar J-login">
            <img src="@/icons/image/default-tx.png">
            <span class="caret" />
          </div>
        </div>
        <form
          action="/query"
          target="_blank"
          class="search-form"
          data-actform="search-click"
        >
          <input
            name="kw"
            class="search"
            type="search"
            maxlength="32"
            placeholder="找影视剧、影人、影院"
            autocomplete="off"
          >
          <input class="submit" type="button" value="">
        </form>
      </div>
    </div>
    <el-dialog title="开通会员" :visible.sync="dialogVisible" width="60%">
      <div class="vip-content">
        <div class="mod_combo">
          <div class="combo_list_wp">
            <ul class="combo_list">
              <li
                class="list_item"
                :class="{ active: curRmb == 0 }"
                @click="onClick(0, 15)"
              >
                <div class="product_item">
                  <h5 class="title">包月</h5>
                  <div class="price">
                    ¥
                    <em>15</em>
                    元
                  </div>
                </div>
              </li>
              <li
                class="list_item"
                :class="{ active: curRmb == 1 }"
                @click="onClick(1, 45)"
              >
                <div class="product_item">
                  <h5 class="title">包季</h5>
                  <div class="price">
                    ¥
                    <em>45</em>
                    元
                  </div>
                </div>
              </li>
              <li
                class="list_item"
                :class="{ active: curRmb == 2 }"
                @click="onClick(2, 168)"
              >
                <div class="product_item">
                  <h5 class="title">包年</h5>
                  <div class="price">
                    ¥
                    <em>168</em>
                    元
                  </div>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <div class="mod_pay">
          <div class="figure">
            <img src="@/icons/image/comm_cgi.png" alt="">
          </div>
          <div class="detail">
            <span>
              支付
              <strong>{{ curMoney }}</strong>
              元
            </span>
            <span> 账号：admin </span>
          </div>
        </div>
        <div class="btn" style="text-align: center; margin-top: 30px">
          <el-button type="primary" @click="onSubmit">确认开通会员</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  name: 'CinemaAdminHead',

  data() {
    return {
      dialogVisible: false,
      curPath: '',
      curRmb: 0,
      curMoney: 15
    }
  },
  computed: {
    ...mapGetters(['userInfo'])
  },
  mounted() {
    this.curPath = this.$route.path
  },

  methods: {
    onClick(i, moeny) {
      this.curRmb = i
      this.curMoney = moeny
    },
    async onSubmit() {
      const allAccount = await this.$localStorage.getItem('allAccount')
      let info = ''
      const newAccount = allAccount.map((item) => {
        if (item.username === this.userInfo.username) {
          const obj = {
            vip: true
          }
          info = Object.assign(item, obj)
          return info
        }
        return item
      })
      await this.$localStorage.setItem('allAccount', newAccount)
      this.$store.dispatch('user/getInfo', Object.assign({}, info))
      this.$message.success('开通会员成功')
      this.dialogVisible = false
    },
    async logout() {
      await this.$localStorage.removeItem('curUser')
      this.$router.push(`/login`)
    }
  }
}
</script>

<style lang="scss" scoped>
.mod_pay {
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  margin-top: 20px;
  width: 100%;
  height: 194px;
  border: 2px solid #f0f0f0;
  border-radius: 12px;
  .figure {
    padding: 10px;
    border: 2px solid #f0f0f0;
    width: 128px;
    height: 128px;
    position: relative;
    margin-right: 30px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .detail {
    color: #000028;
    font-size: 16px;
    line-height: 20px;
    display: flex;
    flex-direction: column;
    span {
      margin-bottom: 10px;
    }
    strong {
      font-size: 36px;
      font-weight: 700;
      color: #000028;
      margin: 0 5px;
    }
  }
}
.header form,
.header h3,
.header input,
.header li,
.header ul {
  padding: 0;
  margin: 0;
  list-style: none;
  border: none;
}

.header {
  position: fixed;
  top: 0;
  z-index: 999;
  width: 100%;
  min-width: 1200px;
  background-color: #fff;
  border-bottom: 1px solid #d8d8d8;
}

.header .header-inner {
  width: 1200px;
  margin: 0 auto;
  height: 80px;
}

.header-placeholder {
  height: 81px;
}

.header .logo {
  background: url(../../../icons/image/logo.png) no-repeat 0;
  background-size: contain;
  overflow: hidden;
  margin-right: 20px;
}

.header .logo,
.header a.logo {
  float: left;
  width: 133px;
  height: 60px;
  margin-top: 10px;
}

.header a.logo {
  line-height: 100em;
}

.header .nav {
  background-color: #fff;
  overflow: hidden;
  width: 530px;
  float: left;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-pack: justify;
  -webkit-justify-content: space-between;
  -ms-flex-pack: justify;
  justify-content: space-between;
}

.header .nav div {
  float: left;
  -webkit-box-flex: 1;
  -webkit-flex: 1;
  -ms-flex: 1;
  flex: 1;
}
.more {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-orient: horizontal;
  -webkit-box-direction: normal;
  -webkit-flex-direction: row;
  -ms-flex-direction: row;
  flex-direction: row;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
}

.more:hover {
  border-color: #d8d8d8;
  border-bottom-color: #fff;
  border-left: 0.1px solid #dcd4d7;
  border-right: 0.1px solid #dcd4d7;
}

.more:hover .configlist {
  display: block;
}

.more:hover .caret {
  -webkit-transform: rotate(180deg);
  -ms-transform: rotate(180deg);
  transform: rotate(180deg);
}

.more:hover:after {
  content: " ";
  position: absolute;
  bottom: -1px;
  left: 1px;
  right: 1px;
  background-color: #fff;
  z-index: 200;
}

.more .apptext {
  float: left;
  display: inline-block;
  font-size: 18px;
  color: #000;
  height: 24px;
  line-height: 24px;
  margin: 0 7px;
}

.more .caret {
  float: left;
  position: relative;
}

.more .configlist {
  display: none;
  width: 66px;
  position: absolute;
  top: 80px;
  background-color: #fff;
  border: 0.1px solid #dcd4d7;
  border-top: 0;
}

.more .configlist .config-item {
  color: #000;
  font-size: 18px !important;
  height: 0 !important;
  line-height: 35px !important;
  height: 35px !important;
}

.header .nav div a {
  text-align: center;
  display: inline-block;
  height: 80px;
  line-height: 80px;
  width: 100%;
  font-size: 18px;
  color: #333;
}

.header .nav div a:hover {
  color: #ef4238;
}

.header .nav div a.active {
  color: #fff;
  background-color: #ef4238;
}

.header form {
  float: right;
  margin: 20px 10px 0 0;
  position: relative;
}

.header form input {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
}

.header form .search {
  display: inline-block;
  height: 40px;
  line-height: 1.2;
  width: 220px;
  padding: 0 40px 0 20px;
  border: 1px solid #ccc;
  font-size: 14px;
  border-radius: 30px;
  background-color: #faf8fa;
  overflow: hidden;
  color: #333;
  outline: none;
}

.ie8 .header form .search {
  padding-top: 11px;
}

.header form .submit {
  display: inline-block;
  position: absolute;
  left: 180px;
  top: 0;
  height: 40px;
  width: 40px;
  background-color: #ef4238;
  border-radius: 30px;
  background-image: url();
  cursor: pointer;
}

.header .user-info {
  float: right;
  position: relative;
  z-index: 9999;
  height: 100%;
}

.header .user-info .user-avatar {
  display: block;
  border: 1px solid transparent;
  border-top: none;
  border-bottom: none;
  padding: 0 10px;
  width: 56px;
  height: 100%;
}

.header .user-info .user-avatar img {
  margin-top: 20px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
}

.header .user-info .user-avatar .caret {
  position: absolute;
  top: 39px;
  right: 10px;
}

// .header .user-info .user-avatar:hover {
//   border-color: #d8d8d8;
// }

// .header .user-info .user-avatar:hover .caret {
//   -webkit-transform: rotate(180deg);
//   -ms-transform: rotate(180deg);
//   transform: rotate(180deg);
// }

.header .user-info .user-avatar:hover .user-menu {
  display: block;
}

// .header .user-info .user-avatar:hover:after {
//   content: " ";
//   position: absolute;
//   height: 10px;
//   bottom: -1px;
//   left: 1px;
//   right: 1px;
//   background-color: #fff;
// }

.header .user-info .user-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 80px;
  border: 1px solid #d8d8d8;
  background-color: #fff;
  font-size: 14px;
  color: #333;
  text-align: right;
  padding: 15px 10px 5px;
  text-align: center;
}

.header .user-info .user-menu li {
  margin-bottom: 6px;
}

.header .user-info .user-menu li > a {
  color: #999;
  display: block;
  word-break: keep-all;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header .user-info .user-menu li > a:hover {
  color: #ef4238;
  text-decoration: underline;
}

.header .user-info .user-menu li.text {
  word-break: keep-all;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.header .user-info .no-login-menu {
  padding: 15px 24px 5px;
}

.mod_combo .list_item {
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  display: inline-block;
  position: relative;
  width: 146px;
  height: 146px;
  border: 2px solid #f0f0f0;
  border-radius: 10px;
  margin-right: 20px;
  text-align: center;
  cursor: pointer;
  &.active {
    border-color: #ebc96a;
    background-color: #fcf7e6;
  }
  .title {
    font-size: 18px;
    font-weight: 600;
    color: #222;
    margin-top: 18px;
  }
  .price {
    font-family: Arial, sans-serif;
    color: #dfb349;
    font-size: 16px;
    font-weight: 700;
    margin-top: -5px;
    text-indent: -8px;
    em {
      font-size: 36px;
    }
  }
  .desc {
    font-size: 15px;
    color: #979797;
    line-height: 20px;
    padding: 0 10px;
    margin-top: 10px;
  }
}
</style>
